module.exports = {
  checkParams(paramsObj) {
    for (let key in paramsObj) {
      console.log("checkParams--key: %s--value: %s==", key, paramsObj[key])
      if (paramsObj[key] === undefined) {
        throw new Error(`参数不全，缺少参数${key}`)
      }
    }
  },
  handleCreateIsSuccess(data) {
    if (data instanceof Array && data.length === 2) {
      return data[1]
    }
    return false
  },
  // 错误代码处理
  errorBody(error) {
    const errorData = {
      SequelizeUniqueConstraintError: { code: -1, msg: "新增数据失败" },
      unknown: { code: 500, msg: "操作失败" }
    }
    if (error) {
      if (error.name && errorData[error.name]) {
        return errorData[error.name]
      }
    }
    return errorData.unknown
  }
}
